package com.ruoyi.business.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

import com.ruoyi.business.service.IAccommodationFeeService;
import com.ruoyi.business.domain.AccommodationFee;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宿舍缴费历史
 *
 * @author songzhengsheng
 * @date 2023-09-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/fee")
public class AccommodationFeeController extends BaseController {

    private final IAccommodationFeeService iAccommodationFeeService;

    /**
     * 查询宿舍缴费历史列表
     */
    @GetMapping("/list")
    public TableDataInfo<AccommodationFee> list(AccommodationFee entity) {
        startPage();
    LambdaQueryWrapper<AccommodationFee> lqw =iAccommodationFeeService.buildQueryWrapper(entity);
    List<AccommodationFee> list = iAccommodationFeeService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出宿舍缴费历史列表
     */
    @Log(title = "宿舍缴费历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AccommodationFee entity, HttpServletResponse response) {
        LambdaQueryWrapper<AccommodationFee> lqw =iAccommodationFeeService.buildQueryWrapper(entity);
        List<AccommodationFee> list = iAccommodationFeeService.list(lqw);
        ExcelUtil.exportExcel(list, "宿舍缴费历史", AccommodationFee.class, response);
    }

    /**
     * 获取宿舍缴费历史详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<AccommodationFee> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iAccommodationFeeService.getById(id));
    }

    /**
     * 新增宿舍缴费历史
     */
    @Log(title = "宿舍缴费历史", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AccommodationFee bo) {
        bo.setCreateTime(new DateTime());
        return toAjax(iAccommodationFeeService.save(bo));
    }

    /**
     * 修改宿舍缴费历史
     */
    @Log(title = "宿舍缴费历史", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AccommodationFee bo) {
        return toAjax(iAccommodationFeeService.updateById(bo));
    }

    /**
     * 删除宿舍缴费历史
     *
     * @param ids 主键串
     */
    @Log(title = "宿舍缴费历史", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iAccommodationFeeService.removeBatchByIds(Arrays.asList(ids), true));
    }
}
